﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Messenger.DataAccess.Attributes
{
    /// <summary>
    /// Mandatory validation
    /// Created by: Dinh Quoc Vuong
    /// Created date: Oct 6th 2011
    /// </summary>
    public class MandatoryValidationAttribute : ValidationBaseAttribute
    {
        #region constuctors
        public MandatoryValidationAttribute() : base() { }

        public MandatoryValidationAttribute(string message)
            : base(message)
        {
        }
        #endregion

        #region overrides
        /// <summary>
        /// Validate mandatory
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Validate(object obj)
        {
            bool isValid = false;
            if (obj != null)
            {
                isValid = true;
                if (obj.GetType() == typeof(string))
                {
                    string value = (string)obj;
                    isValid = value != string.Empty;
                }
            }
            return isValid;
        }

        /// <summary>
        /// Get error message
        /// </summary>
        /// <param name="propertyName">your property name</param>
        /// <returns></returns>
        public override string GetErrorMessage(string propertyName = null)
        {
            string msg = Message ?? ("Property " + propertyName + " is mandatory.");
            return msg;
        }
        #endregion
    }
}
